package ui;

import beans.ErrorPayload;
import beans.OrdinaryPayload;
import beans.TimeDelayPayload;
import burp.*;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import result.AttackResult;
import result.ModelRoot;
import util.BurpCallbacks;

import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.table.AbstractTableModel;
import javax.swing.table.DefaultTableModel;
import javax.swing.table.TableCellEditor;
import javax.swing.table.TableModel;
import javax.swing.text.StyledEditorKit;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.*;
import java.util.List;

/**
 * Created by shuaidong on 2017/7/1.
 */
public class UI2  extends AbstractTableModel implements ITab, IMessageEditorController,Observer {

    private PrintWriter stdout;
    private IBurpExtenderCallbacks callbacks;
    private IContextMenuInvocation contextMenuInvocation;
    private IMessageEditor requestViewer;
    private IMessageEditor responseViewer;
    private IHttpRequestResponse currentDisplayItem;
    private javax.swing.JPanel mainPane;
    private javax.swing.JToggleButton sqlInjectSwitchButton;
    private javax.swing.JCheckBox paramInUrlcheckBox;
    private javax.swing.JCheckBox paramInCookiescheckBox;
    private javax.swing.JCheckBox paramInBodyCheckBox;
    private javax.swing.JPanel settingsPanel;
    private javax.swing.JLabel ordinaryLabel;
    private javax.swing.JLabel errorLabel;
    private javax.swing.JLabel timeDelayLabel;
    private javax.swing.JTable ordinaryTable;
    private javax.swing.JTable timeDelayTable;
    private javax.swing.JTable errorTable;
    private javax.swing.JScrollPane timeDelayScrollPane;
    private javax.swing.JScrollPane errorScrollPane;
    private javax.swing.JScrollPane ordinaryScrollPane;
    private javax.swing.JButton timeDelayButton;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton ordinaryButton;
    private javax.swing.JButton errorButton;
    private javax.swing.JButton hostBlackButton;
    private javax.swing.JButton hostWhiteButton;
    private javax.swing.JButton urlSuffixButton;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JScrollPane hostWhiteScrollPane;
    private javax.swing.JScrollPane hostBlackjScrollPane;
    private javax.swing.JScrollPane urlSuffixScrollPane;
    private javax.swing.JSplitPane jSplitPane2;
    private javax.swing.JTextArea hostWhiteListTextArea;
    private javax.swing.JTextArea hostBlackListTextArea;
    private javax.swing.JTextArea urlSuffixTextArea;
    private javax.swing.JScrollPane scrollPane;
    private Table table;
    public UI2(IBurpExtenderCallbacks callbacks) {
        this.callbacks = callbacks;
        this.stdout = new PrintWriter(callbacks.getStdout(),true);
        ModelRoot.getModelRootInstance().addObserver(this);
        mainPane = new javax.swing.JPanel();
        sqlInjectSwitchButton = new javax.swing.JToggleButton("sqlInject is off",false);
        paramInUrlcheckBox = new javax.swing.JCheckBox("paramInUrl",true);
        paramInCookiescheckBox = new javax.swing.JCheckBox("paramInCookies",true);
        paramInBodyCheckBox = new javax.swing.JCheckBox("paramInBody",true);
        jSplitPane2 = new javax.swing.JSplitPane(javax.swing.JSplitPane.VERTICAL_SPLIT);

        table = new  Table(this);

        this.scrollPane = new JScrollPane(table);
        jSplitPane2.setTopComponent(scrollPane);

        JTabbedPane tabs = new JTabbedPane();
        requestViewer = callbacks.createMessageEditor(this,false);
        responseViewer = callbacks.createMessageEditor(this,false);
        tabs.addTab("Request",requestViewer.getComponent());
        tabs.addTab("Response",responseViewer.getComponent());
        jSplitPane2.setBottomComponent(tabs);
        jSplitPane2.setBackground(new java.awt.Color(255, 255, 255));
        jSplitPane2.setForeground(new java.awt.Color(255, 255, 255));
        jSplitPane2.setResizeWeight(0.5);
        jSplitPane2.setDividerLocation(200);
        settingsPanel = new javax.swing.JPanel();
        ordinaryTable = new JTable();
        ordinaryLabel = new javax.swing.JLabel();
        errorLabel = new javax.swing.JLabel();
        errorTable = new javax.swing.JTable();
        timeDelayLabel = new javax.swing.JLabel();
        timeDelayTable = new javax.swing.JTable();
        timeDelayScrollPane = new javax.swing.JScrollPane();
        errorScrollPane = new javax.swing.JScrollPane();
        ordinaryScrollPane = new javax.swing.JScrollPane();
        hostWhiteScrollPane = new javax.swing.JScrollPane();
        hostWhiteListTextArea = new javax.swing.JTextArea();
        hostBlackjScrollPane = new javax.swing.JScrollPane();
        hostBlackListTextArea = new javax.swing.JTextArea();
        urlSuffixScrollPane = new javax.swing.JScrollPane();
        urlSuffixTextArea = new javax.swing.JTextArea();
        ordinaryButton = new javax.swing.JButton();
        errorButton = new javax.swing.JButton();
        timeDelayButton = new javax.swing.JButton();
        hostBlackButton = new javax.swing.JButton();
        hostWhiteButton = new javax.swing.JButton();
        urlSuffixButton = new javax.swing.JButton();
        jPanel4 = new javax.swing.JPanel();
        jLabel4 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();



        settingsPanel.setForeground(new java.awt.Color(255, 255, 255));
        settingsPanel.setSize(new java.awt.Dimension(200, 100));

        errorLabel.setText("<html><strong><font color=\"SandyBrown\">errorInjectPayloadSets</font></strong></html>");

        timeDelayLabel.setFont(new java.awt.Font("Al Bayan", 0, 13)); // NOI18N
        timeDelayLabel.setText("<html><strong><font color=\"SandyBrown\">timeDelayInjectPayloadSets</font></strong></html>");

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 1085, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
                jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 172, Short.MAX_VALUE)
        );

        timeDelayTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                        {null}
                },
                new String [] {
                        "timeDelayPayload"
                }
        ));
        timeDelayScrollPane.setViewportView(timeDelayTable);

        errorTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                        {null, null}
                },
                new String [] {
                        "pageNormalPayload", "pageContainErrorKeyword"
                }
        ));
        errorScrollPane.setViewportView(errorTable);

        jLabel4.setText("<html><strong><font color=\"SandyBrown\">list</font></strong></html>");

        ordinaryTable.setModel(new javax.swing.table.DefaultTableModel(
                new Object [][] {
                        {null, null}
                },
                new String [] {
                        "pageNormalPayload", "pageAbNormalPayload"
                }
        ));
        ordinaryScrollPane.setViewportView(ordinaryTable);
        ordinaryLabel.setText("<html><strong><font color=\"#SandyBrown\">ordinaryInjectionPayloadSets</font></strong></html>");
        hostWhiteListTextArea.setColumns(20);
        hostWhiteListTextArea.setRows(5);
        hostWhiteListTextArea.setText("host白名单");
        hostWhiteScrollPane.setViewportView(hostWhiteListTextArea);

        hostBlackListTextArea.setColumns(20);
        hostBlackListTextArea.setRows(5);
        hostBlackListTextArea.setText(Model.getInstanceModel().getHostBlackList());
        hostBlackjScrollPane.setViewportView(hostBlackListTextArea);

        urlSuffixTextArea.setColumns(20);
        urlSuffixTextArea.setRows(5);
        urlSuffixTextArea.setText(Model.getInstanceModel().getFileSuffixBlackList());
        urlSuffixScrollPane.setViewportView(urlSuffixTextArea);

        timeDelayButton.setText("add");
       /* timeDelayButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });*/

        jButton2.setText("add");
      /*  jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
*/
        ordinaryButton.setText("add");
      /*  ordinaryButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });*/

        errorButton.setText("add");
       /* errorButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });*/

        hostBlackButton.setText("add");
        /*hostBlackButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton5ActionPerformed(evt);
            }
        });*/

        hostWhiteButton.setText("add");
       /* jButton6.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton6ActionPerformed(evt);
            }
        });*/

        urlSuffixButton.setText("add");
     /*   urlSuffixButton.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton7ActionPerformed(evt);
            }
        });*/

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(settingsPanel);
        settingsPanel.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addGap(15, 15, 15)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING)
                                        .addComponent(timeDelayButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(ordinaryButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(errorButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(hostBlackButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(hostWhiteButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(urlSuffixButton, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(urlSuffixScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(hostWhiteScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(timeDelayScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(hostBlackjScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE))
                                                .addGap(36, 36, 36)
                                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addComponent(timeDelayLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(errorScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(ordinaryScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 296, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(ordinaryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGap(0, 0, Short.MAX_VALUE))
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addGap(16, 16, 16)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 67, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(1413, Short.MAX_VALUE)))
        );
        jPanel3Layout.setVerticalGroup(
                jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel3Layout.createSequentialGroup()
                                .addComponent(ordinaryLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(ordinaryScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 41, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(ordinaryButton))
                                .addGap(12, 12, 12)
                                .addComponent(errorLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(errorScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 40, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(errorButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                .addComponent(timeDelayLabel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addGap(33, 33, 33)
                                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(timeDelayScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
                                                        .addGroup(jPanel3Layout.createSequentialGroup()
                                                                .addComponent(timeDelayButton)
                                                                .addGap(0, 0, Short.MAX_VALUE)))
                                                .addGap(27, 27, 27)
                                                .addComponent(jLabel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                                        .addComponent(hostBlackjScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                        .addComponent(hostBlackButton))))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 14, Short.MAX_VALUE)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(hostWhiteScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, 107, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(hostWhiteButton))
                                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addComponent(urlSuffixScrollPane, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addComponent(urlSuffixButton))
                                .addContainerGap())
                        .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                .addGroup(jPanel3Layout.createSequentialGroup()
                                        .addGap(73, 73, 73)
                                        .addComponent(jButton2, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                                        .addContainerGap(528, Short.MAX_VALUE)))
        );

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(mainPane);
        mainPane.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addContainerGap()
                                                .addComponent(jSplitPane2, javax.swing.GroupLayout.PREFERRED_SIZE, 800, javax.swing.GroupLayout.PREFERRED_SIZE)
                                                .addGap(46, 46, 46)
                                                .addComponent(settingsPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 372, Short.MAX_VALUE))
                                        .addGroup(jPanel1Layout.createSequentialGroup()
                                                .addGap(14, 14, 14)
                                                .addComponent(sqlInjectSwitchButton)
                                                .addGap(18, 18, 18)
                                                .addComponent(paramInUrlcheckBox)
                                                .addGap(18, 18, 18)
                                                .addComponent(paramInCookiescheckBox)
                                                .addGap(18, 18, 18)
                                                .addComponent(paramInBodyCheckBox)
                                                .addGap(0, 0, Short.MAX_VALUE)))
                                .addContainerGap())
        );
        jPanel1Layout.setVerticalGroup(
                jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGroup(jPanel1Layout.createSequentialGroup()
                                .addGap(14, 14, 14)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                                        .addComponent(sqlInjectSwitchButton)
                                        .addComponent(paramInUrlcheckBox)
                                        .addComponent(paramInCookiescheckBox)
                                        .addComponent(paramInBodyCheckBox))
                                .addGap(18, 18, 18)
                                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                        .addComponent(settingsPanel, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                                        .addComponent(jSplitPane2))
                                .addContainerGap(11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 528, Short.MAX_VALUE)
        );
        jPanel2Layout.setVerticalGroup(
                jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                        .addGap(0, 2, Short.MAX_VALUE)
        );
    }

    public void  getUI(){
        Model.getInstanceModel();
        sqlInjectSwitchButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Model.getInstanceModel().setSwitchSqlinject(!Model.getInstanceModel().isSwitchSqlinject());
                if (e.getActionCommand().equalsIgnoreCase("sqlInject is on")){
                    sqlInjectSwitchButton.setText("sqlInject is off");
                }else {
                    sqlInjectSwitchButton.setText("sqlInject is on");
                }


            }
        });
        paramInUrlcheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Model.getInstanceModel().setParamInUrl(!Model.getInstanceModel().isParamInUrl());
                if (paramInUrlcheckBox.isSelected()){
                    paramInUrlcheckBox.setSelected(true);
                }else {
                    paramInUrlcheckBox.setSelected(false);
                }
            }
        });
        paramInBodyCheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Model.getInstanceModel().setParamInBody(!Model.getInstanceModel().isParamInBody());
            }
        });
        paramInCookiescheckBox.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                Model.getInstanceModel().setParamInCookies(!Model.getInstanceModel().isParamInCookies());
            }
        });

        ordinaryButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {

                DefaultTableModel tableModel = (DefaultTableModel)ordinaryTable.getModel();
                int rowCount = tableModel.getRowCount();
                for (int i=0;i<rowCount;i++){
                    String pageNomalPayload = (String) tableModel.getValueAt(i,0);
                    String pageAbnomalPaylod = (String) tableModel.getValueAt(i,1);
                    if (StringUtils.isEmpty(pageNomalPayload)||StringUtils.isEmpty(pageAbnomalPaylod)){
                        JOptionPane.showMessageDialog(settingsPanel,"When input is complete, enter enter build");
                        return;
                    }
                    OrdinaryPayload ordinaryPayload = new OrdinaryPayload(pageNomalPayload,pageAbnomalPaylod);
                    Model.getInstanceModel().getOrdinaryPayloadList().add(ordinaryPayload);
                    tableModel.removeRow(i);
                    tableModel.addRow(new Object[]{null,null});
                  //  JOptionPane.showMessageDialog(settingsPanel,"saved...");

                }
            }
        });

        errorButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                DefaultTableModel tableModel = (DefaultTableModel) errorTable.getModel();
                int rowCount = tableModel.getRowCount();
                for (int i=0;i<rowCount;i++){
                    String leadingMiskString = (String) tableModel.getValueAt(i,0);
                    String mistake = (String) tableModel.getValueAt(i,1);
                    if (StringUtils.isEmpty(leadingMiskString)||StringUtils.isEmpty(mistake)){
                        JOptionPane.showMessageDialog(settingsPanel,"When input is complete, enter enter build or be not null");
                        return;
                    }
                    String[] mistakeArray =  mistake.split("\\|");
                    List<String> mistakeList = new ArrayList<String>();
                    for (int j=0;j<mistakeArray.length;j++){
                        mistakeList.add(mistakeArray[i]);
                    }
                    ErrorPayload errorPayload = new ErrorPayload(leadingMiskString,mistakeList);
                    Model.getInstanceModel().getErrorPayloadList().add(errorPayload);
                    tableModel.removeRow(i);
                    tableModel.addRow(new Object[]{null,null});
                    try {
                        callbacks.getStdout().write((mistake+"---").getBytes());
                    } catch (IOException e1) {
                        e1.printStackTrace();
                    }
                   // JOptionPane.showMessageDialog(settingsPanel,"saved...");
                }

            }
        });
        timeDelayButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                DefaultTableModel tableModel = (DefaultTableModel)timeDelayTable.getModel();
                int rowCount = tableModel.getRowCount();
                for (int i=0;i<rowCount;i++){
                    String timeDelayPalod = (String) tableModel.getValueAt(i,0);
                    if (StringUtils.isEmpty(timeDelayPalod)){
                        JOptionPane.showMessageDialog(settingsPanel,"When input is complete, enter enter build or be not null");
                    }
                    TimeDelayPayload delayPayload =  new TimeDelayPayload(timeDelayPalod,5L);
                    Model.getInstanceModel().getTimeDelayPayloadList().add(delayPayload);
                    tableModel.removeRow(i);
                    tableModel.addRow(new Object[]{null,null});
                }

            }
        });

        hostBlackButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String hostBlackString = hostBlackListTextArea.getText().trim();
                if (hostBlackString.equals("host黑名单")||StringUtils.isEmpty(hostBlackString)){
                    JOptionPane.showMessageDialog(settingsPanel,"When input is complete, enter enter build or be not null");
                }
              //  Model.getInstanceModel().getHostBlackList() =  Model.getInstanceModel().getHostBlackList()+"";
                Model.getInstanceModel().setHostBlackList(Model.getInstanceModel().getHostBlackList()+"|"+hostBlackString);
                hostBlackListTextArea.setText("");
            }
        });

        hostWhiteButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String hostWhiteString = hostWhiteListTextArea.getText().trim();
                if (hostWhiteString.equals("host白名单")||StringUtils.isEmpty(hostWhiteString)){
                    JOptionPane.showMessageDialog(settingsPanel,"When input is complete, enter enter build or be not null");
                }
                Model.getInstanceModel().setHostWhiteList(Model.getInstanceModel().getHostWhiteList()+"|"+hostWhiteString);
                hostWhiteListTextArea.setText("");
            }
        });

        urlSuffixButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String urlSuffix = urlSuffixTextArea.getText().trim();
                if (urlSuffix.equals("URL后缀黑名单")||StringUtils.isEmpty(urlSuffix)){
                    JOptionPane.showMessageDialog(settingsPanel,"When input is complete, enter enter build or be not null");
                }
                Model.getInstanceModel().setFileSuffixBlackList(Model.getInstanceModel().getFileSuffixBlackList()+"|"+urlSuffix);
                urlSuffixTextArea.setText("");
            }
        });
    //    this.scrollPane.add;
        //table.addM








        this.callbacks.customizeUiComponent(this.mainPane);
        this.callbacks.customizeUiComponent(this.jPanel2);
        this.callbacks.addSuiteTab(UI2.this);

    }
    public String getTabCaption() {
        return "EMSqlInjectCheck";
    }

    public Component getUiComponent() {
        return this.mainPane;
    }

    public IHttpService getHttpService() {
        return currentDisplayItem.getHttpService();
    }

    public byte[] getRequest() {
        return currentDisplayItem.getRequest();
    }

    public byte[] getResponse() {
        return currentDisplayItem.getResponse();
    }

    public int getRowCount() {

        return ModelRoot.getModelRootInstance().getAttackResultLinkedList().size();
    }

    public int getColumnCount() {
        return 5;
    }

    public Object getValueAt(int rowIndex, int columnIndex) {
        AttackResult attackResult =  ModelRoot.getModelRootInstance().getAttackResultLinkedList().get(rowIndex);
        switch (columnIndex){
            case 0:
                return attackResult.getSqlInjectType();
            case 1:
                return attackResult.getUrl();
            case 2:
                return attackResult.getInsertParam();
            case 3:
                return attackResult.getPageNomalPayload();
            case 4:
                return attackResult.getPageAbNomalPayload();
            default:
                return "";
        }

    }

    public void update(Observable o, Object arg) {
        AttackResult attackResult = (AttackResult) arg;
        int row = ModelRoot.getModelRootInstance().getAttackResultLinkedList().size();
        fireTableRowsInserted(row, row);

    }

    public class Table extends JTable{
        public Table(TableModel tableModel){
            super(tableModel);
        }

        public void mouseRightClick(java.awt.event.MouseEvent event){
            if (event.getButton()== MouseEvent.BUTTON3){
               // List<IContextMenuFactory> factories = callbacks.getContextMenuFactories();
             //   InputEvent event1 = contextMenuInvocation.getInputEvent();


            }
        }





        @Override
        public void changeSelection(int rowIndex, int columnIndex, boolean toggle, boolean extend) {
            AttackResult attackResult = ModelRoot.getModelRootInstance().getAttackResultLinkedList().get(rowIndex);

            requestViewer.setMessage(attackResult.getBaseHttpResponse().getRequest(),true);
            responseViewer.setMessage(attackResult.getBaseHttpResponse().getResponse(),false);
            currentDisplayItem = attackResult.getBaseHttpResponse();

            super.changeSelection(rowIndex, columnIndex, toggle, extend);
        }

    }

    private class PayloadsTable extends JTable{
        @Override
        public void setValueAt(Object aValue, int row, int column) {
            TableCellEditor cellEditor = this.getCellEditor(row, column);

            super.setValueAt(cellEditor.getCellEditorValue(), row, column);
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column){
            case 0:
                return "sqlInjcetType";
            case 1:
                return "URL";
            case 2:
                return "insertPointParam";
            case 3:
                return "PageNomalPayload";
            case 4:
                return "PageAbnomalPayload";
            default:
                return "";
        }
    }
    @Override
    public Class<?> getColumnClass(int columnIndex) {
        return String.class;
    }

    public static void main(String[] args) {
        boolean a = true;
        System.out.println(!a);
    }
}
